﻿/// <reference path="jquery-1.6.4-vsdoc.js" />

(function ($) {

    $.articleImpl = {

        init: function () {
            $.articleImpl.registerAndHandleExpandCommentClicks();
            $.articleImpl.handleEmptyParagraphs();
        },

        handleEmptyParagraphs: function () {
            //            var paragraphs = $("#articleContent p");
            //            for (var i = 0; i < paragraphs.length; i++) {
            //                if ($(paragraphs[i]).html() == "&nbsp;") {
            //                    $(paragraphs[i]).attr("display", "inline"); //.html("");
            //                }
            //            }
        },

        registerAndHandleExpandCommentClicks: function () {
            $("#comments").delegate(".expandCommentButton", "click", function () {
                var id = this.id.replace(/expandComment/, "");
                var container = $("#leaveComment" + id);
                if (container.css('display') == 'none') {
                    container.slideDown(600);
                }
                else {
                    container.slideUp(600);
                }
            });
        },

        registerValidationForNewComments: function () {
            $(".postCommentContainer form").each(function () {
                $(this).validate({
                    focusInvalid: false,
                    rules: {
                        name: "required",
                        Email: {
                            required: true,
                            email: true
                        },
                        text: "required"
                    },
                    messages: {
                        name: "Please specify your name.",
                        Email: {
                            required: "Your email address is used as a gravatar.",
                            email: "Your email address must be in the format of name@domain.com"
                        },
                        text: "Please say something meaningful."
                    }
                });
            });
        },

        refreshHashFocusForDynamicTemplates: function () {
            var hash = window.location.hash;
            if (window.location.hash != '') {
                window.location.hash = "";
                window.location.hash = hash;
            }
        }
    };

    $.article = function () {
        new $.articleImpl.init();
    };

    $.article.validatationSetup = function () {
        $.articleImpl.registerValidationForNewComments();
    };

    $.article.refreshAnchor = function () {
        $.articleImpl.refreshHashFocusForDynamicTemplates();
    };
})(jQuery); 